package com.csw.alink;

import com.alibaba.alink.common.MLEnvironmentFactory;
import com.alibaba.alink.pipeline.Pipeline;
import com.alibaba.alink.pipeline.PipelineModel;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.java.BatchTableEnvironment;
import org.apache.flink.types.Row;

public class Demo02Model {
    public static void main(String[] args) throws Exception{

        //构建flink 批处理环境
        ExecutionEnvironment env = MLEnvironmentFactory.getDefault().getExecutionEnvironment();

        //创建table环境
        BatchTableEnvironment bsEen = BatchTableEnvironment.create(env);

        //需要分类的数据
        DataSource<String> dataSource = env.fromElements("赞同,爱让我们懂得更多！,");

        Table table = bsEen.fromDataSet(dataSource, "text");


        //加载模型
        PipelineModel model = PipelineModel.load("alink/data/model");


        //分类
        Table transform = model.transform(table);

        transform.printSchema();

        //将table 转换成DS, 打印结果
        bsEen.toDataSet(transform, Row.class).print();
    }
}
